package com.ruoyi.erp.util;

import cn.hutool.core.util.ObjectUtil;

/**
 * @description erp工具类
 * @author chenyun
 * @version 1.0
 * @date 2022/3/13 12:35
 */
public class ErpUtil {
    private ErpUtil() {
        throw new IllegalStateException("不能初始化erp工具类");
    }

    /**
     * 流水号转换编码
     * @param src 流水号
     * @param length 长度
     * @param fillChar 填充字符
     * @param truncate 超出长度是否截断
     * @return
     */
    public static String serialNum2Str(Long src, Integer length, char fillChar ,boolean truncate) {
        if (ObjectUtil.isNull(src)){
            return "";
        }
        String num = src.toString();
        if (length == null || length<1){
            return num;
        }
        if (truncate && num.length()>length) {
            return num.substring(0, length);
        }
        if (num.length()<length){
            return String.format("%"+fillChar+length+"d", src);
        }
        return num;
    }
}
